
package com.rolemodulemiddlemodule.dao;
import com.rolemodulemiddlemodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbRoleModuleMiddleDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbRoleModuleMiddle tbRoleModuleMiddle=null;
    private List<TbRoleModuleMiddle> tbRoleModuleMiddleList=null;

    public boolean add(TbRoleModuleMiddle inTbRoleModuleMiddle){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_RoleModuleMiddle(RoleId,ModuleId,UserAction,CreateTime) values(?,?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setInt(1,inTbRoleModuleMiddle.getRoleId());
        pt.setInt(2,inTbRoleModuleMiddle.getModuleId());
        pt.setInt(3,inTbRoleModuleMiddle.getUserAction());
        pt.setString(4,inTbRoleModuleMiddle.getCreateTime());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public boolean del(int inRoleModuleMiddleId){
        return UtilDAO.del("Tb_RoleModuleMiddle", "RoleModuleMiddleId", inRoleModuleMiddleId);
    }
    public boolean edit(TbRoleModuleMiddle inTbRoleModuleMiddle){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_RoleModuleMiddle set RoleModuleMiddleId=?,RoleId=?,ModuleId=?,UserAction=?,CreateTime=? where RoleModuleMiddleId=?";
        pt = conn.prepareStatement(sql);
        
        pt.setInt(1,inTbRoleModuleMiddle.getRoleModuleMiddleId());
        pt.setInt(2,inTbRoleModuleMiddle.getRoleId());
        pt.setInt(3,inTbRoleModuleMiddle.getModuleId());
        pt.setInt(4,inTbRoleModuleMiddle.getUserAction());
        pt.setString(5,inTbRoleModuleMiddle.getCreateTime());
        pt.setInt(6,inTbRoleModuleMiddle.getRoleModuleMiddleId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public TbRoleModuleMiddle getTbRoleModuleMiddleByRoleModuleMiddleId(int inRoleModuleMiddleId) {
        tbRoleModuleMiddle=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_RoleModuleMiddle where RoleModuleMiddleId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inRoleModuleMiddleId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbRoleModuleMiddle == null)tbRoleModuleMiddle = getTbRoleModuleMiddle(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbRoleModuleMiddle;
    }
    public List<TbRoleModuleMiddle> getTbRoleModuleMiddleAll() {
        tbRoleModuleMiddleList=new ArrayList<TbRoleModuleMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_RoleModuleMiddle";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbRoleModuleMiddleList.add(getTbRoleModuleMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbRoleModuleMiddleList;
    }
    public List<TbRoleModuleMiddle> getTbRoleModuleMiddleAll(VskPage vp) {
        tbRoleModuleMiddleList=new ArrayList<TbRoleModuleMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_RoleModuleMiddle";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_RoleModuleMiddle", "RoleModuleMiddleId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbRoleModuleMiddleList.add(getTbRoleModuleMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbRoleModuleMiddleList;
    }
    public TbRoleModuleMiddle getTbRoleModuleMiddle(ResultSet rs) throws Exception{
        TbRoleModuleMiddle tbRoleModuleMiddle = new TbRoleModuleMiddle();
        tbRoleModuleMiddle.setRoleModuleMiddleId(rs.getInt("RoleModuleMiddleId"));
        tbRoleModuleMiddle.setRoleId(rs.getInt("RoleId"));
        tbRoleModuleMiddle.setModuleId(rs.getInt("ModuleId"));
        tbRoleModuleMiddle.setUserAction(rs.getInt("UserAction"));
        tbRoleModuleMiddle.setCreateTime(rs.getString("CreateTime"));
        return tbRoleModuleMiddle;
    }
    
    
    /**
     * 张庆玉
     */
    public List<TbRoleModuleMiddle> getTbRoleModuleMiddleByRoleId(int roleId) {
        tbRoleModuleMiddleList=new ArrayList<TbRoleModuleMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_RoleModuleMiddle where RoleId="+roleId;
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbRoleModuleMiddleList.add(getTbRoleModuleMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbRoleModuleMiddleList;
    }
}
